package com.lingnan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lingnan.mapper.ActiveMapper;
import com.lingnan.pojo.Active;
import com.lingnan.pojo.ActiveHistory;
import com.lingnan.pojo.History;
import com.lingnan.service.HistoryService;
import com.lingnan.mapper.HistoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author kang
* @description 针对表【tb_history】的数据库操作Service实现
*/
@Service
public class HistoryServiceImpl extends ServiceImpl<HistoryMapper, History>
    implements HistoryService{

    @Autowired
    ActiveMapper activeMapper;

    @Autowired
    HistoryMapper historyMapper;

    @Override
    public List<ActiveHistory> getByNo(String no) {
        LambdaQueryWrapper<History> historyLambdaQueryWrapper = new LambdaQueryWrapper<>();
        historyLambdaQueryWrapper.eq(History::getNo, no).orderByDesc(History::getId);
        List<ActiveHistory> activeList = new ArrayList<>();
        for (History history : historyMapper.selectList(historyLambdaQueryWrapper)) {
            ActiveHistory activeHistory = new ActiveHistory();
            Active active = activeMapper.selectById(history.getActiveId());
            activeHistory.setActive(active);
            activeHistory.setTime(history.getTime());
            activeList.add(activeHistory);
        }
        return activeList;
    }
}




